home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_gzip.py < prev    next >
Text File  |  2005-11-19  |  2KB  |  83 lines

  1. from test.test_support import verify, TESTFN
  2. import sys, os
  3. import gzip
  4.  
  5. filename = TESTFN
  6.  
  7. data1 = """  int length=DEFAULTALLOC, err = Z_OK;
  8.   PyObject *RetVal;
  9.   int flushmode = Z_FINISH;
  10.   unsigned long start_total_out;
  11.  
  12. """
  13.  
  14. data2 = """/* zlibmodule.c -- gzip-compatible data compression */
  15. /* See http://www.cdrom.com/pub/infozip/zlib/ */
  16. /* See http://www.winimage.com/zLibDll for Windows */
  17. """
  18.  
  19. f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50) ; f.close()
  20.  
  21. f = gzip.GzipFile(filename, 'r') ; d = f.read() ; f.close()
  22. verify(d == data1*50)
  23.  
  24. # Append to the previous file
  25. f = gzip.GzipFile(filename, 'ab') ; f.write(data2 * 15) ; f.close()
  26.  
  27. f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
  28. verify(d == (data1*50) + (data2*15))
  29.  
  30. # Try .readline() with varying line lengths
  31.  
  32. f = gzip.GzipFile(filename, 'rb')
  33. line_length = 0
  34. while 1:
  35.     L = f.readline(line_length)
  36.     if L == "" and line_length != 0: break
  37.     verify(len(L) <= line_length)
  38.     line_length = (line_length + 1) % 50
  39. f.close()
  40.  
  41. # Try .readlines()
  42.  
  43. f = gzip.GzipFile(filename, 'rb')
  44. L = f.readlines()
  45. f.close()
  46.  
  47. f = gzip.GzipFile(filename, 'rb')
  48. while 1:
  49.     L = f.readlines(150)
  50.     if L == []: break
  51. f.close()
  52.  
  53. # Try seek, read test
  54.  
  55. f = gzip.GzipFile(filename)
  56. while 1:
  57.     oldpos = f.tell()
  58.     line1 = f.readline()
  59.     if not line1: break
  60.     newpos = f.tell()
  61.     f.seek(oldpos)  # negative seek
  62.     if len(line1)>10:
  63.         amount = 10
  64.     else:
  65.         amount = len(line1)
  66.     line2 = f.read(amount)
  67.     verify(line1[:amount] == line2)
  68.     f.seek(newpos)  # positive seek
  69. f.close()
  70.  
  71. # Try seek, write test
  72. f = gzip.GzipFile(filename, 'w')
  73. for pos in range(0, 256, 16):
  74.     f.seek(pos)
  75.     f.write('GZ\n')
  76. f.close()
  77.  
  78. f = gzip.GzipFile(filename, 'r')
  79. verify(f.myfileobj.mode == 'rb')
  80. f.close()
  81.  
  82. os.unlink(filename)
  83.